package com.ahocorasick.controller;

import com.ahocorasick.service.SensitiveWordService;
import com.ahocorasick.service.impl.SensitiveWordServiceImpl;
import org.ahocorasick.trie.Emit;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Collection;

@RestController
@RequestMapping("/api/sensitive")
public class SensitiveWordController {

    @Resource
    private SensitiveWordService sensitiveWordService;

//    @PostMapping("/match")
//    public ResponseEntity<?> matchSensitiveWords(@RequestBody String text){
//        Collection<Emit> tokens = sensitiveWordService.findSensitiveWords(text);
//        return ResponseEntity.ok(tokens);
//    }

    @PostMapping("/match")
    public ResponseEntity<Collection<SensitiveWordServiceImpl.SensitiveWordResult>> matchSensitiveWords(@RequestBody String text){
        Collection<SensitiveWordServiceImpl.SensitiveWordResult> tokens = sensitiveWordService.findSensitiveWords(text);
        return ResponseEntity.ok(tokens);
    }

}
